package neuronvisualizer;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;

public class SectionGUI extends javax.swing.JPanel {

        private Driver parent;
        private JLabel[][] sectionToggles;
        private JLabel[] sectionData;
        private int columns;
        
        private Color HIDDEN = new Color(103,103,103);
        private Color SHOWN = new Color(78,184,85);
        private Color NA = new Color(0,0,0);

    /** Creates new form SectionGUI */
    public SectionGUI(Driver p) {
        parent = p;
        initComponents();        
    }
    
    public void reset(){
    	for(int i=0;i<columns;i++){
    		for(int j=0;j<4;j++){
    			sectionToggles[i][j].setBackground(HIDDEN);
    			
    		}
    	}
    	setSectionData(null);
    }
    
    private void initComponents() {
        this.setSize(200,300);
        this.setLayout(null);           
        
        //columns = parent.getSectionColumnCount();
        columns = 5;
        sectionToggles = new JLabel[4][columns];
        
        for(int i=0;i<4;i++){
                for(int j=0;j<columns;j++){
                        sectionToggles[i][j] = new JLabel("");
                        sectionToggles[i][j].setBounds(10+(30*j),(30*i)+100,28,28);
                        sectionToggles[i][j].setOpaque(true);
                        sectionToggles[i][j].setBackground(HIDDEN);
                        sectionToggles[i][j].addMouseListener(
                                new MouseListener(){
                                                public void mouseClicked(MouseEvent arg0) {
                                                        toggleSection((JLabel)arg0.getSource());
                                                }
                                                public void mouseEntered(MouseEvent arg0) {
                                                        setSectionData((JLabel)arg0.getSource());
                                                }
                                                public void mouseExited(MouseEvent arg0) {
                                                        setSectionData(null);
                                                }
                                                public void mousePressed(MouseEvent arg0) {}
                                                public void mouseReleased(MouseEvent arg0) {}
                                }
                        );
                        this.add(sectionToggles[i][j]);
                }
        }
        
        sectionData = new JLabel[7];
        for(int i=0;i<7;i++){
                sectionData[i] = new JLabel();
                sectionData[i].setBounds(10,0+(i*15),170,25);
                this.add(sectionData[i]);
        }
        sectionData[0].setText("Choose a Section");
        sectionData[1].setText("to view more data");
        sectionData[2].setText("");
        sectionData[3].setText("");
        sectionData[4].setText("");
        sectionData[5].setText("");
        sectionData[6].setText("");     
    }
    
    public void setSectionData(JLabel section){
        if(section==null){
                sectionData[0].setText("Choose a Section");
                sectionData[1].setText("to view more data");
                sectionData[2].setText("");
                sectionData[3].setText("");
                sectionData[4].setText("");
                sectionData[5].setText("");
                sectionData[6].setText("");
        }
        else{
                Section s = null;
                for(int i=0;i<4;i++){
                        for(int j=0;j<columns;j++){
                                if(sectionToggles[i][j]==section){
                                        s = parent.getSection(i,j);
                                }
                        }
                }
                
                String[] t = parent.sectionData(s);
                for(int i=0;i<7;i++){
                        sectionData[i].setText(t[i]);
                }
        }
    }
    
    public void toggleSection(JLabel section){
        for(int i=0;i<4;i++){
                for(int j=0;j<columns;j++){
                        if(sectionToggles[i][j]==section){
                                if(sectionToggles[i][j].getBackground()==HIDDEN){
                                        sectionToggles[i][j].setBackground(SHOWN);
                                        parent.showSection(i,j);
                                }
                                else if(sectionToggles[i][j].getBackground()==SHOWN){
                                        sectionToggles[i][j].setBackground(HIDDEN);
                                        parent.hideSection(i,j);
                                }
                        }
                }
        }
    }



}